package page.actionPage;

import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ListView;
import javafx.scene.layout.VBox;
import lombok.Getter;
import lombok.Setter;
import utils.Constant;
import utils.ControllerUtils;

import java.util.function.Function;

public class TemplateController extends page.BasePage {

    @FXML
    private Button submitButton;
    @FXML
    public Button cancleButton;
    @FXML
    public ListView<Object> variableList;
    // 主界面
    @FXML
    public VBox vBox;
    @Setter
    @Getter
    private String url;


    public void initTemplate(Function<Button, page.BasePage> submitFun) {
        submitButton.setOnMouseClicked(mouseEvent -> {
            // 保存 url
            page.BasePage basepage = submitFun.apply(submitButton);
            if (basepage instanceof ActionPage) {
                basepage.db.saveInData(Constant.DB.PAGE_NAME, ((ActionPage) basepage).getComboxName());
                basepage.db.saveInData(Constant.DB.TYPE, ((ActionPage) basepage).getTYPE());
            }
            ControllerUtils.closePane(root);
        });

        // 设置取消按钮
        cancleButton.setOnMouseClicked(MouseEvent -> ControllerUtils.closePane(root));

    }

}
